home *** CD-ROM | disk | FTP | other *** search
/ New Star Software Collection / NSS_Collection.iso / 3-170 dbase 10 for windows / 1.ima / SAMPLES.PAK / SAMPPROC.PRG < prev    next >
Text File  |  1993-07-26  |  39KB  |  1,187 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Sampproc.prg
  3. *
  4. *  WRITTEN BY:   Borland Late Night Crew
  5. *
  6. *  DATE:         7/22/93
  7. *
  8. *  UPDATED:
  9. *
  10. *  VERSION:      Alpha α
  11. *
  12. *  DESCRIPTION:  This is the procedure file called by all Bladerunner samples.
  13. *
  14. *  PARAMETERS:   None
  15. *
  16. *  CALLS:
  17. *
  18. *  USAGE:        SET PROCEDURE TO Sampproc
  19. *
  20. *
  21. *******************************************************************************
  22.  
  23.  
  24. ********************************** Classes ************************************
  25.  
  26. *** Class for Focus2.prg
  27. *******************************************************************************
  28. class MyWindow of Window()
  29. *  Called by Focus2.prg
  30. *******************************************************************************
  31.    this.top =  100       && window pixel row
  32.    this.width = 300      && window pixel width
  33.    this.clickcount = 0   && variable indicating number of times the mouse
  34.                          && was clicked in this window.  Incremented in the
  35.                          && OnLeftMouseDown event handler function
  36.    this.button = new Pushbutton(this)  && pushbutton of this, the window
  37.    this.button.width = 100   && width of pushbutton
  38.    this.button.caption = "Pushbutton"
  39.    this.button.left = 85
  40.    this.button.height = 40
  41.  
  42.    *******************************************************************************
  43.    function OnGotFocus
  44.    *  Sets this window's caption when this window has focus.
  45.    *******************************************************************************
  46.       this.caption = "I have focus"
  47.       return .t.
  48.  
  49.    *******************************************************************************
  50.    function OnLostFocus
  51.    *  Changes the title of this window when another window obtains focus.
  52.    *******************************************************************************
  53.       this.caption = "I have focus NOT"
  54.       return .t.
  55.  
  56.    *******************************************************************************
  57.    function OnLeftMouseDown
  58.    *  When the mouse is clicked inside this window, increments the count of
  59.    *  clicks in the window, which basically amounts to the number of times
  60.    *  the window has been in focus since the program was started.
  61.    *******************************************************************************
  62.        parameters x,y,flags
  63.        this.clickcount = this.clickcount+1
  64.        this.button.caption = ltrim(str(this.clickcount))
  65.     return .t.
  66.  
  67.  
  68. endclass
  69.  
  70. *** Classes for Puzzle.prg
  71.  
  72. *******************************************************************************
  73. class MenuWindow of Window
  74. *
  75. * Called by Puzzle.prg
  76. *******************************************************************************
  77.     private Puzzle,Draw
  78.  
  79.     this.height = 150
  80.     this.width = 240
  81.     this.caption = "Create New Windows"
  82.  
  83.     Puzzle = new PushButton(this)
  84.     Puzzle.Caption = "New Puzzle Window"
  85.     Puzzle.enabled = .t.
  86.     Puzzle.OnLeftMouseDown = MakePuzzle   && Create puzzle when left mouse
  87.                                           && button is pressed
  88.     Puzzle.top = 5
  89.     Puzzle.Left = 5
  90.     Puzzle.Width = 200
  91.  
  92.     Draw = new PushButton(this)
  93.     Draw.Caption = "New Draw Window"      && Create the Ray painter when left
  94.                                           && mouse button is pressed
  95.     Draw.enabled = .t.
  96.     Draw.OnLeftMouseDown = MakeDraw
  97.     Draw.top = 30
  98.     Draw.Left = 5
  99.     Draw.Width = 200
  100.  
  101.     Paint = new PushButton(this)
  102.     Paint.Caption = "New Paint Window"
  103.     Paint.enabled = .t.
  104.     Paint.OnLeftMouseDown = MakePaint     && Create the Line painter when left
  105.                                           && mouse button is pressed
  106.     Paint.top = 55
  107.     Paint.Left = 5
  108.     Paint.Width = 200
  109.  
  110.  
  111. endclass
  112.  
  113.  
  114.  
  115. *******************************************************************************
  116. class DrawWindow of window
  117.  
  118. * Defines the ray painting window.
  119. *
  120. * Called by Puzzle.prg
  121. *******************************************************************************
  122.  
  123.     this.visible = .f.
  124.     this.caption = "Press Mouse And Move"  && when you press the mouse, move
  125.                                            && it, and let go, a series of rays
  126.                                            && will appear with the origin at
  127.                                            && the point where you pressed down
  128.                                            && the mouse
  129.  
  130.     *-- set the initial size of the window
  131.     this.height = 400
  132.     this.width = 400
  133.     this.visible = .t.
  134.     this.xpos = 0
  135.     this.ypos = 0
  136.     this.hDc = 0
  137.     this.pen = 0
  138.  
  139.     * Color pushbuttons
  140.     this.red = new PushButton(this)
  141.     this.red.Caption = "RED"
  142.     this.red.enabled = .t.
  143.     this.red.OnLeftMouseDown = PushedButton  && OnLeftMouseDown event handler
  144.     this.red.top =  this.height - 80
  145.     this.red.Left = 5
  146.     this.red.Width = 50
  147.     this.red.colorval = 255
  148.     this.red.owner = this    && parent window
  149.  
  150.     this.blue = new PushButton(this)
  151.     this.blue.Caption = "BLUE"
  152.     this.blue.enabled = .t.
  153.     this.blue.OnLeftMouseDown = PushedButton
  154.     this.blue.top =  this.height - 80
  155.     this.blue.Left = 60
  156.     this.blue.Width = 50
  157.     this.blue.colorval = 255
  158.     this.blue.owner = this
  159.  
  160.     this.green = new PushButton(this)
  161.     this.green.Caption = "GREEN"
  162.     this.green.enabled = .t.
  163.     this.green.OnLeftMouseDown = PushedButton
  164.     this.green.top =  this.height - 80
  165.     this.green.Left = 115
  166.     this.green.Width = 50
  167.     this.green.colorval = 255
  168.     this.green.owner = this
  169.  
  170.     *************************************************
  171.     function Init
  172.     *  Initializes the window
  173.     *************************************************
  174.         junk = this.OnSize(0,0,0)
  175.     junk = this.SetButtonColor()
  176.     return .f.
  177.  
  178.     *************************************************
  179.     function OnLeftMouseDown
  180.     * When the left mouse button is pressed, move to
  181.     * that point
  182.     *************************************************
  183.         parameters x, y, flags
  184.  
  185.         this.xpos = x
  186.         this.ypos = y
  187.         *this.capture = .t.
  188.         this.hDc = GetDC( this.hWnd )
  189.         this.pen = CreatePen(0,1,this.color)
  190.         junk = SelectObject( this.hDc, this.pen )
  191.         junk = MoveTo(this.hDc, this.xpos, this.ypos)
  192.         return .t.
  193.  
  194.     *************************************************
  195.     function OnLeftMouseUp
  196.     * When the button is released, release the current
  197.     * pen used
  198.     *************************************************
  199.         parameters x, y, flags
  200.         private i
  201.  
  202.         *this.capture = .f.
  203.         i = ReleaseDC(this.hWnd, this.hDc)
  204.         this.hDc = 0
  205.         i = DeleteObject(this.pen)
  206.         this.pen = 0
  207.         return .t.
  208.  
  209.     *************************************************
  210.     function OnMouseMove
  211.  
  212.     * When the mouse is being moved, draw a line from
  213.     * the point where the mouse button was pressed to
  214.     * each point the mouse moves to.  This creates rays.
  215.     *************************************************
  216.         parameters x, y, flags
  217.         private junk
  218.  
  219.         if this.hDc <> 0
  220.             junk = MoveTo(this.hDc, this.xpos, this.ypos)
  221.             junk = LineTo(this.hDc, x, y )
  222.         endif
  223.         return .t.
  224.  
  225.     *************************************************
  226.     function OnSize
  227.     *************************************************
  228.         parameters top, left, width
  229.  
  230.         this.red.top = this.height - 80
  231.         this.green.top = this.height - 80
  232.         this.blue.top = this.height - 80
  233.         return .f.
  234.  
  235.     *************************************************
  236.     function SetButtonColor
  237.     *  Sets the color of the current rays.
  238.     *************************************************
  239.         private dc,brush, r
  240.  
  241.         this.color = RGB(this.red.colorval, this.green.colorval, this.blue.colorval)
  242.         dc = GetDC(this.hwnd)
  243.         brush = CreateSolidBrush(this.color)
  244.         r = Rect(this.green.left+this.green.width+5,this.height-80, 50, 50)
  245.         * Fill a small rectangle with the current color
  246.         junk = FillRect(dc,r,brush)
  247.         junk = ReleaseDC(this.hwnd,dc)
  248.         junk = DeleteObject(brush)
  249.         return .f.
  250.  
  251. endclass
  252.  
  253.  
  254. *******************************************************************************
  255. class PaintWindow of DrawWindow
  256. * Defines the Line painter window
  257. *
  258. * Called by Puzzle.prg
  259. *******************************************************************************
  260.  
  261.     this.caption = "Draw Lines"
  262.  
  263.     *************************************************
  264.     function OnMouseMove
  265.     *  When the mouse is moved, draw a line from the
  266.     *  last position using the current color.  This
  267.     *  creates a continuous line as you move the mouse.
  268.     *************************************************
  269.         parameters x, y, flags
  270.         private junk
  271.         if this.hDc <> 0
  272.             junk = LineTo(this.hDc, x, y )
  273.         endif
  274.         return .f.
  275.  
  276. endclass
  277.  
  278.  
  279. *******************************************************************************
  280. class Puzzle of window
  281. * Creates a window with a 15 button puzzle
  282. *
  283. * Called by Puzzle.prg
  284. *******************************************************************************
  285.     private i, parent, junk
  286.  
  287.     this.visible = .f.
  288.     this.caption = "Puzzle"
  289.  
  290.     *-- set the initial size of the window
  291.     this.height = 400
  292.     this.width = 400
  293.  
  294.  
  295.  
  296.     *-- set the current position of the hole
  297.     this.holex = 4
  298.     this.holey = 4
  299.  
  300.     parent = this
  301.  
  302.     *-- create 15 buttons inside the window.
  303.     for i = 1 to 4
  304.         for j = 1 to 4
  305.             if(i*j <> 16)
  306.                 globx = i
  307.                 globy = j
  308.                 b = new ButtonTile()
  309.             endif
  310.         next
  311.     next
  312.  
  313.     *************************************************
  314.     function Show
  315.     *************************************************
  316.         private i
  317.         i = this.OnSize(0,0,0)
  318.         this.visible = .t.
  319.         return .t.
  320.  
  321.     *************************************************
  322.     function OnSize
  323.     *  If the puzzle window is resized, resize the
  324.     *  buttons too.
  325.     *************************************************
  326.         parameters top, left, width
  327.         private h,w,b,i
  328.  
  329.         *-- BUG: account for menu width and scroll bars
  330.         this.h=this.height-100
  331.         this.w=this.width-50
  332.  
  333.         h = this.h/4
  334.         w = this.w/4
  335.  
  336.  
  337.         * redefine dimensions for the 15 buttons.
  338.         for i = 1 to 15
  339.             b = this[i]
  340.             b.visible = .f.    && invisible so don't see flashing
  341.             b.top = (b.y-1)*h
  342.             b.left = (b.x-1)*w
  343.             b.width = w
  344.             b.height = h
  345.             b.enabled = .t.
  346.         next
  347.         * make them all visible
  348.         for i = 1 to 15
  349.             this[i].visible = .t.
  350.         next
  351.         return .f.
  352.  
  353.     *************************************************
  354.     function MoveButton
  355.     *  When a button is moved, assign it a new location,
  356.     *  and put a hole in its previous location.
  357.     *************************************************
  358.         parameter b
  359.         private x,y, i, j, number,o
  360.  
  361.         if abs(this.holex-b.x) + abs(this.holey-b.y) = 1
  362.  
  363.             b.visible =.f.
  364.  
  365.             x = this.holex
  366.             this.holex = b.x
  367.             b.x = x
  368.  
  369.             y = this.holey
  370.             this.holey = b.y
  371.             b.y = y
  372.  
  373.             b.top = this.h/4 * (b.y-1)
  374.             b.left = this.w/4 * (b.x-1)
  375.  
  376.             b.visible = .t.
  377.             i = this.CheckWinner()   && check if all buttons in place
  378.         endif
  379.         return .f.
  380.  
  381.     *************************************************
  382.     function CheckWinner
  383.     *  If all the buttons are in place, change the
  384.     *  caption of the window to "Winner".
  385.     *************************************************
  386.         private i
  387.  
  388.         *-- check the position of each button for the correct position
  389.         for i = 1 to 15
  390.             if this[i].index <> (this[i].x-1)*4+this[i].y-1
  391.                 return .f.
  392.             endif
  393.         next
  394.  
  395.         *-- Set the caption of all the buttons to winner
  396.         for i = 1 to 15
  397.             this[i].caption = "Winner"
  398.         next
  399.         return .t.
  400.  
  401. endclass
  402.  
  403.  
  404.  
  405. *** Classes for Event.prg
  406.  
  407. *-- BUG: should be able to pass parameter to subobject's constructor.  There
  408. *       is an implied parameter 'parent' to button Tile that currently has to
  409. *       be passed as a global.
  410. *
  411. *class ButtonTile(parent, globx, globy) of Button(parent)
  412. *******************************************************************************
  413. class ButtonTile of PushButton(parent)
  414. * Creates a puzzle button.
  415. *
  416. * Called by Event.prg
  417. *******************************************************************************
  418.  
  419.     this.index = (globx-1)*4+globy-1
  420.     this.caption = str(this.index+1,2)
  421.     this.puzzle = parent                && should be unnecessary
  422.     this.x = globx
  423.     this.y = globy
  424.  
  425.     *************************************************
  426.     Function OnLeftMouseDown
  427.     *  When the mouse is pressed, check if the button
  428.     *  can be moved, and move it, if appropriate.
  429.     *************************************************
  430.         parameters x, y, flags
  431.  
  432.         *--BUG: code should read 'parent.MoveButton(this)'
  433.         *
  434.         b = this
  435.         x = this.puzzle.MoveButton(b)
  436.         return .f.
  437. endclass
  438.  
  439. *** Procedures and Functions Called by Contact.prg ***
  440.  
  441.  
  442. ******************************************************************************
  443. procedure Selectcomp
  444.  
  445. * On selection routine for the Comp304 window.  Brings up a regression
  446. * graph if "pushgraph" was selected, a window with a browse object
  447. * if "pushsummar" was selected, and otherwise closes the window.
  448. *
  449. * Called by Contact.prg
  450. ******************************************************************************
  451. private active
  452. active = activecontrol()   && what control was active when selection was made?
  453. do case
  454.    case active = "PUSHGRAPH"
  455.       select summary
  456.       set filter to compcode = company->compcode
  457.       *** BUG in GRAPH FORM -- while/for clauses cause GPF
  458.       graph form activity &&while compcode=company->compcode
  459.       set filter to
  460.       select company
  461.    case active = "PUSHSUMMAR"
  462.       isBrowseUp = .t.
  463.       define window BrowseWind from 10,10 to 25,70 ;
  464.          of application;
  465.          title "BROWSE"
  466.       define browse companyBrowse of BrowseWind from 0,0 to 16,62
  467.  
  468.       open window BrowseWind
  469.       set focus to BrowseWind
  470.    otherwise
  471.     * Cleanup()
  472.     ***BUG -- problems closing the window after closing databases
  473.     * close window Comp304
  474. endcase
  475. return
  476.  
  477. ******************************************************************************
  478. function CloseBrowse
  479. * OnClose function for BrowseWindow
  480. ******************************************************************************
  481. isBrowseUp = .f.
  482. return .t.
  483.  
  484. ******************************************************************************
  485. function Contact_Clean
  486.  
  487. * Close all databases, and select the previous workarea.
  488. *
  489. * Called by Event.prg
  490. ******************************************************************************
  491. on error *               && just in case BrowseWind isn't open
  492. close window BrowseWind
  493. on error
  494. use
  495. use in contact
  496. use in summary
  497. release isBrowseUp
  498. return .t.
  499.  
  500.  
  501. *** End of procedures and functions called by Contact.prg ***
  502.  
  503.  
  504. *** Procedures and Functions called by Event.prg ***
  505.  
  506.  
  507. *******************************************************************************
  508. function MakeButtonWindow
  509.  
  510. * Creates a window with a button that will move to new coordinates inside
  511. * the window when the left mouse button is clicked.
  512. *
  513. * Called by Event.prg
  514. *******************************************************************************
  515.     private o
  516.     o = MakeWindow("Click anywhere to move button")
  517.                                            && Make the window with one button
  518.     o.OnLeftMouseDown=ButtonLeftMouseDown  && Assign the function
  519.                                            && ButtonLeftMouseDown to the event
  520.                                            && OnLeftMouseDown.  This is a
  521.                                            && function pointer assignment.
  522.                                            && The event gets the address of the
  523.                                            && function to be executed.
  524.     o.typewin = "Click anywhere to move button"
  525.     return o
  526.  
  527. *******************************************************************************
  528. function MakeSizeWindow
  529.  
  530. * Creates a window with a button.  This window will get resized as you click
  531. * the left mouse button and move.
  532. *
  533. * Called by Event.prg
  534. *******************************************************************************
  535.     private o
  536.     o = MakeWindow("Click anywhere to resize window")   && create the window
  537.     o.OnMouseMove=MouseMove    && OnMouseMove event handler function
  538.     o.OnLeftMouseDown=LeftMouseDown   && OnLeftMouseDown event handler function
  539.     o.typewin = "Click anywhere to resize window"
  540.     return o
  541.  
  542. *******************************************************************************
  543. Function MakeWindow
  544.  
  545. * Creates a window with one pushbutton
  546. *
  547. * Called by Event.prg
  548. *******************************************************************************
  549.     param captionStart
  550.     private x,o,b
  551.  
  552.     set talk off
  553.     w = "X"+str(c+1000,4)
  554.     b = "B"+str(c+1000,4)
  555.     * Create the window using DEFINE syntax
  556.     define window &w from 1,1 to 50,50 title "Window" MDI sizeable
  557.     define push &b of &w at 10,10 prompt "Button"
  558.     acti window &w
  559.     * get a handle to the defined window using the findwindow() function
  560.     o = findwindow(w)
  561.     o.ourname = w
  562.     o.OnGotFocus=WinGotFocus   && functions handling OnGotFocus and OnLostFocus
  563.     o.OnLostFocus=WinLostFocus && events
  564.  
  565.     o.orgWidth = o.Width
  566.     o.orgHeight = o.Height
  567.     o.WindowNum = c
  568.     o.bc = 1
  569.     o.capStart = captionStart
  570.     c = c + 1
  571.     x= o.OnGotFocus()  && The window has focus initially
  572.     return o
  573.  
  574. *******************************************************************************
  575. function WinGotFocus
  576. * OnGotFocus event handler function for the window
  577. *
  578. * Called by Event.prg
  579. *******************************************************************************
  580.     private w
  581.     this.caption = this.capStart + " -- Got Focus #" + str(this.WindowNum,1)
  582.     w = this.ourname
  583.    *acti window &w
  584.     return .f.
  585.  
  586. *******************************************************************************
  587. procedure WinLostFocus
  588. * OnLostFocus event handler function for the window
  589. *
  590. * Called by Event.prg
  591. *******************************************************************************
  592.     this.caption = this.capStart + " -- Lost Focus #" + str(this.WindowNum,1)
  593.  
  594. *******************************************************************************
  595. function MouseMoveShow
  596. *
  597. * Called by Event.prg
  598. *******************************************************************************
  599.     parameters x, y, flags
  600.     @ 0,0
  601.     ? x,y
  602.  
  603.  
  604. *******************************************************************************
  605. procedure ButtonLeftMouseDown
  606. * OnLeftMouseDown event handler for the window created with MakeButtonWindow()
  607. *
  608. * Called by Event.prg
  609. *******************************************************************************
  610.     parameters x, y, flags
  611.     private w,b,i,j,k
  612.  
  613.     if bits(flags,3)
  614.         j = 0
  615.         k = 0
  616.         x = 0
  617.         y = 0
  618.         for i = 1 to this.bc
  619.             if bits(flags,2)
  620.                 this[i].height = this[i].height * 2
  621.                 this[i].width = this[i].width * 2
  622.             endif
  623.             if j + this[i].height > this.height
  624.                 x = x + k
  625.                 j = 0
  626.             endif
  627.             this[i].left = x
  628.             this[i].top = j
  629.             j = j + this[i].height
  630.             if this[i].width > k
  631.                 k = this[i].width
  632.             endif
  633.         next
  634.     else
  635.         if bits(flags,2)
  636.             this.bc = this.bc + 1
  637.             b = "B"+str(this.bc+1000,4)
  638.             w = this.ourname
  639.             define push &b of &w at 1000,1000 prompt "Button"
  640.         endif
  641.         this[this.bc].caption = ltrim(str(x))+","+ltrim(str(y))
  642.         this[this.bc].left = x
  643.         this[this.bc].top = y
  644.     endif
  645.  
  646. *******************************************************************************
  647. function MouseMove
  648. * Event handler for window created with MakeSizeWindow()
  649. *
  650. * Called by Event.prg
  651. *******************************************************************************
  652.     parameters x, y, flags
  653.     if this.capture
  654.         this.Width = x
  655.         this.Height = y
  656.     endif
  657.     return .f.
  658.  
  659. *******************************************************************************
  660. procedure LeftMouseDown
  661. *  Event handler for window created with MakeSizeWindow()
  662. *
  663. * Called by Event.prg
  664. *******************************************************************************
  665.     parameters x, y, flags
  666.     if this.capture
  667.         this.capture = .f.
  668.     else
  669.         this.capture = .t.
  670.         x = this.OnMouseMove(x,y,flags)
  671.     endif
  672.  
  673.  
  674. *** End of Procedures and Functions called by Event.prg ***
  675.  
  676.  
  677. *** Procedures and Functions called by WinApi ***
  678.  
  679. *******************************************************************************
  680. procedure OnSelApi
  681.  
  682. * On selection routine for the Api window.  Executes the function/group of
  683. * functions specified by the marked radiobutton.  If "Cancel" was pressed,
  684. * the window is closed.
  685. *
  686. * Called by WinApi.prg
  687. *******************************************************************************
  688. private selection
  689. selection = activecontrol()
  690. if selection = "CANCEL"
  691.    set procedure to
  692.    close window Api
  693. else
  694.    if selection = "WINDIR"  && function that returns a result
  695.       ?WinDir()
  696.    else
  697.       do &selection         && don't need to see the results of these
  698.    endif
  699. endif
  700.  
  701.  
  702.  
  703.  
  704.  
  705. ********************************************************************************
  706. function SysInfo
  707.  
  708. * Display information about the system.
  709. *
  710. * Called by WinApi.prg
  711. ********************************************************************************
  712. setup()
  713. getinfo()
  714. showit()
  715. leave()
  716.  
  717.  
  718. ********************************************************************************
  719. FUNCTION gVer
  720.  
  721. * Gets information from the windows function
  722. * GetVersion(), which returns the major and minor
  723. * DOS and Windows versions as a CLONG.
  724. *
  725. *
  726. * The "High Byte of the High Word" contains the
  727. * major DOS version, the "Low Byte of the High Word"
  728. * contains the minor DOS version. The "High Byte of
  729. * the Low Word" specifies the minor version of
  730. * windows and the "Low byte of the Low Word"
  731. * specifies the major windows version. The Bit
  732. * functions are used to extract the proper values.
  733. * BitRshift(), BitAnd().
  734. *
  735. * Called by WinApi.prg
  736. ********************************************************************************
  737. PARAM verType
  738. #define HiWord(x) (bitrshift(bitand(x,4294901760),16))
  739. #define LoWord(x) (bitand(x,65535))
  740. #define HiByte(x) (ltrim(str(bitrshift(bitand(x,65280),8))))
  741. #define LoByte(x) (ltrim(str(bitand(x,255))))
  742. EXTERN PASCAL CLONG GetVersion( )  krnl386.exe
  743. z=GetVersion( )
  744. IF UPPER(verType)="DOS"
  745.   RETURN HiByte(HiWord(z))+"."+LoByte(HiWord(z))
  746. ENDIF
  747. IF LEFT(UPPER(verType),3)="WIN"
  748.   RETURN  LoByte(LoWord(z))+"."+HiByte(LoWord(z))
  749. ENDIF
  750.  
  751.  
  752. ********************************************************************************
  753. FUNCTION setup
  754.  
  755. * Called by Sysinfo().  This functions declares all the necessary
  756. * Windows API functions used for displaying system information, and defines
  757. * the window that will display that information.
  758. *
  759. * Called from file WinApi.prg
  760. ********************************************************************************
  761. CLEAR
  762. SET TALK OFF
  763. Public mMode,mCpu,mCoprocess,mFreeMem,mInstance,wFreeMem,hndDBW
  764. hndDBW=_APP.FRAMEWIN.HWND
  765. EXTERN PASCAL CWORD GetWinFlags( )  krnl386.exe
  766. EXTERN PASCAL CWORD GetModuleUsage(CWORD)  krnl386.exe
  767. EXTERN PASCAL CWORD GetModuleHandle(CPTR)  krnl386.exe
  768. EXTERN PASCAL CWORD GetVersion( )  user.exe
  769. EXTERN PASCAL CWORD ShowWindow(CWORD,CWORD)  user.exe
  770. DEFINE WINDOW sysinfo FROM 0,0 TO 19,40 TITLE "Windows System Information";
  771.               OF application SIZEABLE
  772. DEFINE PUSHBUTTON ok OF sysinfo PROMPT "    OK     " at 16,14
  773. ON SELECTION WINDOW sysinfo DO leave
  774. RETURN 0
  775.  
  776. ********************************************************************************
  777. FUNCTION getInfo
  778.  
  779. * Called by Sysinfo().  This function makes the necessary API calls, and assigns
  780. * the accessed information to variables that will be displayed in the window
  781. * showing system information.
  782. *
  783. * Called from file WinApi.prg
  784. ********************************************************************************
  785. mX1=GetModuleHandle("DBASEWIN.EXE") && "SYSINFO"
  786. mInstance=GetModuleUsage(mX1)
  787. x=GetWinFlags()
  788. mMode=IIF(x =BitOr(x,32),"Enhanced Mode",IIF(x=BitOr(x,16),"Standard Mode",;
  789.     IIF(x=BitOr(x,2),"Running Win286","")))
  790. mCpu=IIF(BitOr(x,8)=x,"80486",IIF(x=BitOr(x,4),"80386",IIF(x=BitOr(x,2),"80286",;
  791.     IIF(x=BitOr(x,128),"80186",IIF(x=BitOr(x,64),"8086","")))))
  792. mCoprocess=IIF(x=BitOr(x,1024),"Yes","No ")
  793. mFreeMem=LTRIM(STR(MEMO()))+"K"
  794. extern pascal clong GetFreeSpace( cword )  krnl386.exe
  795. wFreeMem=ltrim(str(GetFreeSpace(0)/1024))+"K"
  796. RETURN 0
  797.  
  798. ********************************************************************************
  799. FUNCTION showIt
  800.  
  801. * Called by Sysinfo().  This function brings up the window with system
  802. * information retrieved by calling Windows API functions through Bladerunner.
  803. *
  804. * Called from file WinApi.prg
  805. ********************************************************************************
  806. CLEAR
  807. ? ShowWindow(hndDBW,7) && 7 make icon no acitve
  808. ACTIVATE WINDOW sysinfo
  809. @  2,2 SAY "Number Of Instances      "+LTRIM(STR(mInstance))
  810. @  4,2 SAY "Windows Version          "+gVer("WIN")
  811. @  6,2 SAY "Mode of Operation        "+mMode
  812. @  8,2 SAY "CPU Type                 "+mCpu
  813. @  10,2 SAY "Coprocessor Present      "+mCoprocess
  814. @ 12,2 SAY "Free Global Memory       "+wFreeMem
  815. @ 14,2 SAY "Dos Version              "+gVer("DOS")
  816.  
  817. readmodal("sysinfo")
  818. RETURN 0
  819.  
  820. ********************************************************************************
  821. FUNCTION leave
  822.  
  823. * Called by Sysinfo().  Releases the window displaying system information.
  824. *
  825. * Called from file WinApi.prg
  826. ********************************************************************************
  827. ? ShowWindow(hndDBW,4) && This works fine by it's self
  828. ACTIVATE SCREEN
  829.  
  830. RELEASE WINDOW sysinfo
  831. RETURN 0
  832.  
  833.  
  834. *******************************************************************************
  835. procedure SysParm
  836.  
  837. * Calls the Windows function SystemParametersInfo( ) for
  838. * seting up the windows desktop wallpaper.
  839. * Displays a getfile box to pick the wallpaper for
  840. * the windows desktop.
  841. *
  842. *  Called by WinApi.prg
  843. *******************************************************************************
  844. EXTERN PASCAL CWORD SystemParametersInfo(CWORD,CWORD,CPTR,CWORD) user.exe
  845. x=GETFILE("*.BMP","dBASE Wallpaper changer")
  846. DO WHILE LEN(x) > 0
  847.   SystemParametersInfo(20,0,x,2)
  848.   x=GETFILE("*.BMP","dBASE Wallpaper changer")
  849. ENDDO
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856. *******************************************************************************
  857. FUNCTION OkCanBox
  858.  
  859. * OkCanBox(<cMess>,<cTitle>).
  860. * <cMess>  = Message to display in Box.
  861. * <cTitle> = Title of Message Box.
  862. *
  863. * Creates a MessageBox on the SCREEN with
  864. * a title and message text. The user must
  865. * press or click OK or CANCEL or press ESCAPE
  866. * key. This is a System Modal MessageBox.
  867. * Calls the Windows function messagebox().
  868. * choice = okcanbox("Read my lips","Message Box")
  869. * 2 if Escape pressed, 1 if OK button pressed,
  870. * 2 if CANCEL pressed. Or 0 if not enough memory.
  871. *
  872. *  Called by WinApi.prg
  873. *******************************************************************************
  874. * Returns 0 if not enough memory to create MessageBox.
  875. * Returns 1=OK,2=CANCEL,3=ABORT,4=RETRY,5=IGNORE,6=YES,7=NO,8=ONE
  876. *   wType any combo of below
  877. *       MODE                         DEFAULT BUTTON
  878. *0x3000h=12288D Mode Mask  0x0F00h=3840 Dec Def.Button
  879. *0x0000h=00000D App Modal  0x0000h=0000 Dec Button 1
  880. *0x1000h=04096D Sys Modal  0x0100h=0256 Dec Button 2
  881. *0x2000h=08192D Task Modal 0x0200h=0512 Dec Button 3
  882. *                          0x0300h=0768 Dec Button 4
  883. *                          0x0400h=1024 Dec Button 5
  884. *                          0x0500h=1280 Dec Button 6
  885. *                          0x0600h=1536 Dec Button 7
  886. *                          0x0700h=1792 Dec Button 8
  887. *        ICON                           BUTTON
  888. *0x00F0h=0240D Icon Mask  0x000Fh=0015Dec Type Mask
  889. *0x0010h=0016D Hand       0x0000h=0000Dec OK Button
  890. *0x0010h=0016D Stop *     0x0001h=0001Dec OK CANCEL
  891. *0x0020h=0032D Question   0x0002h=0002Dec ABORT RETRY IGNORE
  892. *0x0030h=0048D Exclaimation 0003h=0003Dec YES NO CANCEL
  893. *0x0040h=0064D Astrisk    0x0004h=0004Dec YES NO
  894. *0x0040h=0064D Information x0005h=0005Dec RETRY CANCEL
  895. *                         0x0008h=0008Dec ABORT RETRY
  896. *                         0x0009h=0009Dec OK CANCEL ABORT
  897. *                                         RETRY IGNORE
  898. *                         0x000Ah=0010Dec NO CANCEL RETRY
  899. *                                         CANCEL GARBAGE
  900. *                         0x000Bh=0011Dec OK CANCEL ABORT
  901. *                                         RETRY IGNORE YES
  902. *                                         NO CANCEL
  903. *******************************************************************************
  904. PARAMETERS cMess, cTitle
  905. wType=HTOI("1031") && 1031h=4145decimal
  906. cMess1=IIF(ISBLANK(cMess),"Put Message Here! "+CHR(13)+CHR(13)+;
  907.      "Syntax is: "+CHR(13)+"? OkcanBox('Message','Title')"+;
  908.      CHR(13) + CHR(13) + "Returns: " + CHR(13) +;
  909.      "1 if OK button clicked or pressed"+CHR(13)+;
  910.      "2 if Cancel button or Escape key pressed"+CHR(13)+;
  911.      "0 if not enough memory to run",cMess)
  912. cTitle1=IIF(ISBLANK(cTitle),"OkcanBox( ) Message Function",cTitle)
  913. extern pascal cword messagebox(cword,cptr,cptr,cword ) user.exe
  914. npressed=messagebox(0,cMess1,cTitle1,wType)
  915. RETURN npressed
  916.  
  917.  
  918.  
  919.  
  920.  
  921. *******************************************************************************
  922. procedure winwall
  923.  
  924. * Calls the Windows WallPaper changer program.
  925. * First it reduces dBASE to an ICON then it
  926. * changes into the windows directory and displays a
  927. * GETFILE() box of the *.BMP files in the windows
  928. * directory then it changes the desktop wallpaper to
  929. * the file you choose.Next it asks if you want to keep
  930. * the Wallpaper or set it to (None) Then it returns to
  931. * the directory you started from and restores dBASE
  932. * from the ICON.
  933. *
  934. *
  935. *  Called by WinApi.prg
  936. *******************************************************************************
  937. EXTERN PASCAL CWORD SystemParametersInfo(CWORD,CWORD,CPTR,CWORD) user.exe
  938. EXTERN PASCAL CWORD CloseWindow(CWORD) user.exe
  939. EXTERN PASCAL CWORD OpenIcon(CWORD) user.exe
  940. hndDBW=_APP.FRAMEWIN.HWND
  941. CloseWindow(hndDBW)
  942. orgDir  = SET("DIRECTORY")
  943. winPath = winDir()
  944. SET DIRECTORY TO &winPath
  945. x=GETFILE("*.BMP","dBASE Wallpaper changer")
  946. DO WHILE LEN(x) > 0
  947.   SystemParametersInfo(20,0,x,1) && WAS 2
  948.   x=GETFILE("*.BMP","dBASE Wallpaper changer")
  949. ENDDO
  950. blankWall = OkCanBox("Press OK to keep the Wallpaper"+;
  951.         CHR(13)+"or press Cancel to set wallpaper to (None)",;
  952.        "Keep the wallpaper or set to (None) ?")
  953. IF blankWall = 2
  954.    SystemParametersInfo(20,0,"(None)",2)
  955. ENDIF
  956. OpenIcon(hndDBW)
  957. SET DIRECTORY TO &orgDir
  958.  
  959.  
  960.  
  961.  
  962. *******************************************************************************
  963. procedure GetWinTX
  964.  
  965. * Calls the Windows function GetWindowText to get title of the
  966. * Bladerunner frame window
  967. *
  968. *  Called by WinApi.prg
  969. *******************************************************************************
  970.  
  971. dBWhand = _APP.FRAMEWIN.HWND
  972. EXTERN PASCAL CWORD GetWindowText(CWORD,CPTR,CWORD)  user.exe
  973. winTitle = SPACE(80)      && first make empty string to be filled
  974. lenTitle = GetWindowText(dBWhand,winTitle,80)
  975. ? "The Title of dBASEWIN window from API call"
  976. ? winTitle
  977. ?
  978. *  Note: The Object modle allows you to get this information with
  979. *        the following command.
  980. ? _APP.FRAMEWIN.CAPTION
  981. ? "The Title of dBASEWIN window from the Object Model"
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989. *******************************************************************************
  990. procedure Icon
  991.  
  992. * This example just minimizes dBASEWIN.EXE to a
  993. * ICON (by way of the CloseWindow funtion) waits 5
  994. * seconds then restores dBASEWIN.EXE from its ICON.
  995. *
  996. *  Called by WinApi.prg
  997. *******************************************************************************
  998. EXTERN PASCAL CWORD CloseWindow(CWORD)  user.exe
  999. EXTERN PASCAL CWORD OpenIcon(CWORD)  user.exe
  1000. hwnd = _APP.FRAMEWIN.HWND  && gets the window handle for dBASE.
  1001. CloseWindow(hwnd)          && reduce dBASE to an ICON
  1002. INKEY(5)                   && wait 5 seconds
  1003. OpenIcon(hwnd)             && restore dBASE from an ICON
  1004.  
  1005.  
  1006.  
  1007. *******************************************************************************
  1008. FUNCTION  winDir
  1009.  
  1010. * Calls the Windows Funnction GetWindowsDirectory( ) which
  1011. * is used to get the Directory that windows is
  1012. * installed in.
  1013. *
  1014. *  Called by WinApi.prg
  1015. *******************************************************************************
  1016. EXTERN PASCAL CWORD GetWindowsDirectory(CPTR,CWORD) krnl386.exe
  1017. cWinDir = SPACE(144)
  1018. cWinDirLen = GetWindowsDirectory(cWinDir,144)
  1019. return cWinDir
  1020.  
  1021.  
  1022. *** End of Procedures and Functions called by Winapi ***
  1023.  
  1024.  
  1025. *** Procedures and Functions called by Puzzle.prg ***
  1026.  
  1027.  
  1028.  
  1029. *************************************************
  1030. function MakePaint
  1031. *
  1032. *  Called by Puzzle.prg
  1033. *************************************************
  1034.     parameters x, y, flags
  1035.     private p
  1036.  
  1037.     p = new PaintWindow()
  1038.     junk = p.Init()
  1039.     return .f.
  1040.  
  1041. *--BUG: Functions have to appear at the end of the file (after class definitions)
  1042. *
  1043. *************************************************
  1044. function MakePuzzle
  1045. *
  1046. *  Called by Puzzle.prg
  1047. *************************************************
  1048.     parameters x, y, flags
  1049.     private p
  1050.     p = new Puzzle()
  1051.     x = p.Show()
  1052.     return .f.
  1053.  
  1054. *************************************************
  1055. function MakeDraw
  1056. *
  1057. *  Called by Puzzle.prg
  1058. *************************************************
  1059.     parameters x, y, flags
  1060.     private p
  1061.  
  1062.     p = new DrawWindow()
  1063.     junk = p.Init()
  1064.     return .f.
  1065.  
  1066. *************************************************
  1067. function RGB
  1068. *  Creates appropriate color number from the
  1069. *  passed red,green,blue color values
  1070. *
  1071. *  Called by Puzzle.prg
  1072. *************************************************
  1073.     parameter r,g,b
  1074.     return b*65536+g*256+r
  1075.  
  1076. *************************************************
  1077. function Rect
  1078. *  Creates a rectangle
  1079. *
  1080. *  Called by Puzzle.prg
  1081. *************************************************
  1082.     parameter left, top, width, height
  1083.     return MakeInt(left)+MakeInt(top)+MakeInt(width+left)+MakeInt(top+height)
  1084.  
  1085. *************************************************
  1086. function MakeInt
  1087. *
  1088. *  Called by Puzzle.prg
  1089. *************************************************
  1090.     parameter int
  1091.     return chr(bitand(int,255))+chr(bitr(int,8))
  1092.  
  1093. *************************************************
  1094. function PushedButton
  1095. *  Toggles a color button's color being added to
  1096. *  the current painting color mixture.
  1097. *
  1098. *  Called by Puzzle.prg
  1099. *************************************************
  1100.     parameters x, y, flags
  1101.     if isupper(this.caption)
  1102.         this.caption = lower(this.caption)
  1103.         this.colorval = 0
  1104.     else
  1105.         this.caption = upper(this.caption)
  1106.         this.colorval = 255
  1107.     endif
  1108.     junk = this.owner.SetButtonColor()
  1109.     return .f.
  1110.  
  1111.  
  1112.  
  1113. *** End of Procedures and Functions called by Puzzle.prg ***
  1114.  
  1115.  
  1116. *** Procedures and Functions called by OpenWind.prg ***
  1117.  
  1118.  
  1119.  
  1120.  
  1121. *******************************************************************************
  1122. procedure ShowInfo
  1123.  
  1124. * Brings up the Info window.  This window contains text objects that correspond
  1125. * to whatever information was selected for viewing in the previous, SelectInfo
  1126. * window, and an image containing the map of Europe highlighting the currently
  1127. * selected country.  "Cancel" in this window closes it.
  1128. *
  1129. * Called by OpenWind.prg
  1130. *******************************************************************************
  1131. private cnt,countryName,background,newArea
  1132. windCnt = windCnt + 1
  1133. cnt = ltrim(str(windCnt))
  1134. countryName = rtrim(country->name)+cnt  && in case the same country is chosen
  1135.                                         && more than once
  1136. background = iif(mod(windCnt,2)=0,"b","bg")  && alternate background window color
  1137. newArea = ltrim(str(select()))
  1138. if newArea <> "0"
  1139.    use country in select() again alias &countryName
  1140.    select &countryName
  1141.    * don't let the windows go off the screen
  1142.    define window Info&cnt from 2+mod(windCnt*2,20),30 + mod(windCnt,10);
  1143.       to 13+mod(windCnt*2,20),70+mod(windCnt,10) ;
  1144.       of application;
  1145.       title "Info -- " + country->name;
  1146.       sizeable;
  1147.       color w+/&background
  1148.    * show the population field for the current country
  1149.    define text popText of Info&cnt at 2,3 prompt "Population:"
  1150.    define text popInfo of Info&cnt at 3,5 prompt country->population;
  1151.       picture "999,999,999,999" function "T" color rb/&background
  1152.    * show the capital field for the current country
  1153.    define text capText of Info&cnt at 5,3 prompt "Capital:"
  1154.    define text capInfo of Info&cnt at 6,5 prompt upper(country->capital);
  1155.       color rb/&background
  1156.    * show the map of the current country highlighted on a map of Europe
  1157.    define text mapText of Info&cnt at 1,25 prompt country->name;
  1158.       color gr+/&background
  1159.    define image map of Info&cnt from 2,20 to 12,38 memo country->map
  1160.    define pushbutton cancel of Info&cnt at 8,5 prompt "CANCEL" default
  1161.    on selection window Info&cnt close window Info&cnt
  1162.  
  1163.    * OPEN this window, and set focus to it.  This command causes Info to be
  1164.    * added to the list of the currently open windows, but doesn't stop program
  1165.    * control flow at the OPEN line.  This window is not modal.
  1166.    open window Info&cnt
  1167.    set focus to Info&cnt
  1168. else && no more available areas
  1169.    * Cheap warning
  1170.    ?"No more available workareas"
  1171. endif
  1172.  
  1173. return
  1174.  
  1175.  
  1176. *******************************************************************************
  1177. function Clean_Openwindow
  1178.  
  1179. * This function closes the Country database, and releases all public variables.
  1180. *
  1181. * Called by OpenWind.prg
  1182. *******************************************************************************
  1183. use in country
  1184. release windcnt
  1185. return .t.
  1186.  
  1187.